/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
    vector<string> ret;
public:
    vector<string> binaryTreePaths(TreeNode* root) {
        dfs(root, "");
        return ret;
    }
 
    void dfs(TreeNode* root, string path)
    {
        path += to_string(root->val); // 不可能传空root进来
        if(root->left == nullptr && root->right == nullptr)
        {
            ret.push_back(path); // 是叶子结点就push当前路径
        }
        else // 不是叶子结点就先加上箭头
        {
            path += "->";
        }
        if(root->left != nullptr) // 剪枝，此时不用写函数出口
            dfs(root->left, path);
        if(root->right != nullptr)
            dfs(root->right, path);
    }
};